import Vue from 'vue'
import Router from 'vue-router'
import approvals from './approvals'
import attendances from './attendances'
import departments from './departments'
import employees from './employees'
import permission from './permission'
import salarys from './salarys'
import setting from './setting'
import social from './social'
Vue.use(Router)

/* 导入布局，帮助我们绘制了页面整体结构 */
import Layout from '@/layout'

// 动态路由   需要权限认证
export const asyncRoutes = [
  approvals,
  attendances,
  departments,
  employees,
  permission,
  salarys,
  setting,
  social
]
// 静态的路由 不需要进行权限的认证
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/detail',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/employees/detail')
      }
    ]
  },
  {
    path: '/excel',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/excel')
      }
    ]
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

// 对路由进行实例化
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRoutes] // 配置理由规则
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
